package com.zm.Study06_OutputStreamWriter;

import java.io.*;

public class ConversionStreamDemo {
    public static void main(String[] args) throws IOException {
        //不指定字符集，就是默认(UTF-8)，指定在字节流对象后 ，字符集
        OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("D:\\project\\IDEAPROJECT\\JavaIO\\src\\main\\resources\\static\\ReaderAndWriter\\osw.txt"),"GBK");
        osw.write("中国");
        osw.close();

        //不管以上字符流用何种字符集，与他相对应的inputstreamreader都能读懂,但是要与上面的字符集对应
        InputStreamReader isr=new InputStreamReader(new FileInputStream("D:\\project\\IDEAPROJECT\\JavaIO\\src\\main\\resources\\static\\ReaderAndWriter\\osw.txt"),"GBK");
       int by;
       while ((by= isr.read())!=-1){
           System.out.print((char) by);
       }
       isr.close();
    }
}
